package start;
import tool.s;
public class T977 {
    public static void main(String[] args) {
        int [] nums={-3,-2,-1,3,4,5,6};
        int [] r=sortedSquares(nums);
        s.print(r);




    }
    public static int[] sortedSquares(int[] nums) {
        int[] r=new int[nums.length];
        int rr=nums.length-1;
        int left=0;
        int right=nums.length-1;
        while(rr>=0){
            int leftS=nums[left]*nums[left];
            int rightS=nums[right]*nums[right];
            if(leftS>rightS){
                r[rr]=leftS;
                left++;
            }else {
                r[rr]=rightS;
                right--;
            }
            rr--;
        }
        return r;

    }
}
